package scm.erp.core.domain;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.BeanUtils;

import java.lang.reflect.InvocationTargetException;

public interface IConvert {
    Logger log = LoggerFactory.getLogger("convert");

    default <T> T convert(Class<T> tClass) {
        T dto = null;
        try {
            dto = tClass.getDeclaredConstructor().newInstance();
            BeanUtils.copyProperties(this, dto);
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
            log.error("数据转换错误!", e);
            e.printStackTrace();
        }
        return dto;
    }
}